package glassline;

import glassline.Glass.GlassActivity;
import glassline.interfaces.Conveyor;
import glassline.interfaces.Cutter;
import transducer.TChannel;
import transducer.TEvent;
import transducer.TReceiver;
import transducer.Transducer;

public class NCCutterAgent extends ConveyorAgent implements TReceiver, Cutter {

	public NCCutterAgent(Transducer t, Conveyor next_obj) {
		super(t, next_obj, null);
		
		// Register channel with the transducer
	}
	
	// Messages
	/* (non-Javadoc)
	 * @see glassline.Cutter#msgHereIsGlass(glassline.Glass)
	 */

	public void msgHereIsGlass(Glass g) {
		myGlass.add(new MyGlass(g));
		stateChanged();
	}

	/* (non-Javadoc)
	 * @see glassline.Cutter#msgDoneCuttingGlass()
	 */
	public void msgDoneCuttingGlass() {
		stateChanged();
	}

	/* (non-Javadoc)
	 * @see glassline.Cutter#pickAndExecuteAnAction()
	 */
	@Override
	public boolean pickAndExecuteAnAction() {
		// Rule #1
		if (!myGlass.isEmpty()) {
			CutGlass(myGlass.get(0).g);
			return true;
		}
		
		return false;
	}
	
	// Transducer event listener.
	/* (non-Javadoc)
	 * @see glassline.Cutter#eventFired(transducer.TChannel, transducer.TEvent, java.lang.Object[])
	 */
	@Override
	public void eventFired(TChannel channel, TEvent event, Object[] args) {
		super.eventFired(channel, event, args);
	}

	private void CutGlass(Glass g) {
		// TODO: Need animation to know what exactly what it wants.
		// TODO: Listen for this event for unit testing
		Object params[] = new Object[1];
		params[0] = g.recipe;
		myTransducer.fireEvent(TChannel.NCCutter, TEvent.CUT_GLASS, params);
		g.addActivity(GlassActivity.Cut); // Mark glass as cut.
	}
	
	// Unit test stufff
	
	/* (non-Javadoc)
	 * @see glassline.Cutter#printData()
	 */
	@Override
	public void printData() {
		super.printData();
	}
}
